home *** CD-ROM | disk | FTP | other *** search
- /*
- * imggrid.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /* IMGGRID: program superimposes a grid with chosen spacing over an image
- * usage: imggrid imimg outimg [-s SPACING] [-i] [-L]
- *
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <images.h>
- #include <tiffimage.h> /* picfile info on images */
- extern void print_sos_lic ();
-
- #define SPACING 20 /* default spacing of grid */
-
- int usage (short);
- int input (int, char **, long *, short *);
-
- main (argc, argv)
- int argc;
- char *argv[];
- {
- register int x, y; /* image coordinates */
- Image *imgI; /* input, output image pointers */
- unsigned char **imgIn; /* first and second input image */
- long spacing; /* spacing of grid lines */
- short invertFlag; /* invert grid 1/0 for high/low intensity */
- long xSize, ySize; /* sidelengths of image */
-
- /* read user parameter values */
- if ((input (argc, argv, &spacing, &invertFlag)) < 0)
- return (-1);
-
- /* read input image */
- imgI = ImageIn (argv[1]);
- if (imgI->bps == 8 && imgI->spp == 3) {
- printf ("Got RGB image!!!\nInput image must be Grayscale or B&W!!\n");
- exit (1);
- }
- imgIn = imgI->img;
- ySize = ImageGetHeight (imgI);
- xSize = ImageGetWidth (imgI);
-
- /* create image */
- for (y = 0; y < ySize; y++) {
- if ((y % spacing) == 0) {
- for (x = 0; x < xSize; x++) {
- if (invertFlag) {
- if (imgIn[y][x] > 128)
- imgIn[y][x] = 0;
- else
- imgIn[y][x] = 255;
- }
- else
- imgIn[y][x] = 255;
- }
- }
- for (x = 0; x < xSize; x++) {
- if ((x % spacing) == 0) {
- if (invertFlag) {
- if (imgIn[y][x] > 128)
- imgIn[y][x] = 0;
- else
- imgIn[y][x] = 255;
- }
- else
- imgIn[y][x] = 255;
- }
- }
- }
-
- /* write out image */
- ImageOut (argv[2], imgI);
- return (0);
- }
-
-
- /* USAGE: function gives instructions on usage of program
- * usage: usage (flag)
- * When flag is 1, the long message is given, 0 gives short.
- */
-
- int
- usage (flag)
- short flag; /* flag =1 for long message; =0 for short message */
- {
-
- /* print short usage message or long */
- printf ("USAGE: imggrid imimg outimg [-s SPACING] [-i] [-L]\n");
- if (flag == 0)
- return (-1);
-
- printf ("\nimggrid creates test image of grid\n");
- printf ("with chosen spacing.\n\n");
- printf ("ARGUMENTS:\n");
- printf (" inimg: input image filename (TIF)\n");
- printf (" outimg: output image filename (TIF)\n\n");
- printf ("OPTIONS:\n");
- printf (" -s SPACING: spacing of grid lines. Default=%d pixels.\n", SPACING);
- printf (" -i: inverts grid high/low for low/high image.\n");
- printf (" -L: print Software License for this module\n");
-
- return (-1);
- }
-
-
- /* INPUT: function reads input parameters
- * usage: input (argc, argv, &spacing, &invertFlag)
- */
-
- #define USAGE_EXIT(VALUE) {usage (VALUE); return (-1);}
-
- int
- input (argc, argv, spacing, invertFlag)
- int argc;
- char *argv[];
- long *spacing; /* spacing of grid lines */
- short *invertFlag; /* inverts grid 1/0 for image intensity */
- {
- long n;
-
- if (argc == 1 || argc == 2)
- USAGE_EXIT (1);
-
- *spacing = SPACING;
- *invertFlag = 0;
-
- for (n = 3; n < argc; n++) {
- if (strcmp (argv[n], "-s") == 0) {
- if (++n == argc)
- USAGE_EXIT (0);
- *spacing = atol (argv[n]);
- }
- else if (strcmp (argv[n], "-i") == 0)
- *invertFlag = 1;
- else if (strcmp (argv[n], "-L") == 0) {
- print_sos_lic ();
- exit (0);
- }
- else
- USAGE_EXIT (0);
- }
-
- return (0);
- }
-